import 'dart:convert';
import 'dart:io';

// 请求类
class Request {
  final String url = "http://news-at.zhihu.com/api/3/stories/latest";

//获取请求数据 异步
  getDataFromZhihuApi() async {
    var httpClient = new HttpClient(); //创建httpClient对象
    var url = new Uri.http("news-at.zhihu.com", "/api/3/stories/latest"); //创建uri
    var request = await httpClient.getUrl(url); //获取数据 这里是异步的哦
    var response = await request.close(); //关闭请求，等待响应
    return await response.transform(utf8.decoder).join(); //解码响应的内容
  }
}
